<?php

declare(strict_types=1);

namespace app\validate\org;

use app\model\OrgMember;
use think\Validate;

class OrgMemberValidate extends Validate
{
    protected $rule = [
        'id' => 'integer|gt:0',
        'org_id' => 'require|integer|gt:0',
        'user_id' => 'require|integer|gt:0',
        'member_role' => 'require|in:' . OrgMember::ROLE_OWNER . ',' . OrgMember::ROLE_ADMIN . ',' . OrgMember::ROLE_MEMBER,
        'position' => 'max:50',
        'status' => 'in:0,1',
        'invited_by' => 'integer|gt:0',
        'joined_at' => 'date',
    ];

    protected $message = [
        'org_id.require' => '组织ID不能为空',
        'org_id.integer' => '组织ID格式不正确',
        'org_id.gt' => '组织ID格式不正确',
        'user_id.require' => '用户ID不能为空',
        'user_id.integer' => '用户ID格式不正确',
        'user_id.gt' => '用户ID格式不正确',
        'member_role.require' => '成员角色不能为空',
        'member_role.in' => '成员角色不正确',
        'position.max' => '职位描述过长',
        'status.in' => '成员状态不正确',
        'invited_by.integer' => '邀请人格式不正确',
        'invited_by.gt' => '邀请人格式不正确',
        'joined_at.date' => '加入时间格式不正确',
    ];

    protected $scene = [
        'create' => [
            'org_id',
            'user_id',
            'member_role',
            'position',
            'status',
            'invited_by',
            'joined_at',
        ],
        'update' => [
            'id',
            'org_id',
            'user_id',
            'member_role',
            'position',
            'status',
            'invited_by',
            'joined_at',
        ],
    ];
}
